package com.dynamo.transport.network.practise.channel.socket.nio;

import com.dynamo.transport.network.practise.channel.ChannelFuture;
import com.dynamo.transport.network.practise.channel.ChannelPipeline;
import com.dynamo.transport.network.practise.channel.Channels;
import com.dynamo.transport.network.practise.channel.socket.AbstractSocketChannel;

import java.net.SocketAddress;
import java.nio.channels.SocketChannel;

/**
 * @author duanyimiao
 * @create 2018-12-18 10:51 AM
 * @description
 **/
public class NioClientSocketChannel extends AbstractSocketChannel {

    public NioClientSocketChannel(ChannelPipeline pipeline,SocketAddress remoteAddress) {
        try {
            this.remoteAddress = remoteAddress;
            this.pipeline = pipeline;
            this.channel = SocketChannel.open();
            this.channel.configureBlocking(false);
            //创建一个Client Channel
            Channels.fireChannelOpen(pipeline, this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Override
    public ChannelFuture write(Object msg) {

        Channels.write(pipeline,this,msg);
        return null;
    }

    @Override
    public ChannelFuture bind(SocketAddress socketAddress) {
        return null;
    }
}
